package com.itdr.protal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itdr.common.ServerResponse;
import com.itdr.pojo.Category;
import com.itdr.pojo.vo.CategoryVO;
import com.itdr.protal.mapper.CategoryMapper;
import com.itdr.protal.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itdr.utils.VOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AirZhang
 * @since 2020-10-20
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Resource
    CategoryMapper categoryMapper;

    @Override
    public ServerResponse gz(Integer fid) {
        List<CategoryVO> categoryVOS = new ArrayList<>();
        List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().eq("parent_id", fid));
        for (Category category : categoryList) {
            CategoryVO categoryVO = VOUtil.getCategoryVO(category);
            categoryVOS.add(categoryVO);
        }
        return ServerResponse.toSuccess(categoryVOS);
    }
}
